#include "ifeedreader_engine.h"
#include "MainState.h"

#include <set>

using namespace std;

#define NO_ERRORS		0
#define ERROR_TAG_NOT_FOUND	1000
#define ERROR_NEWS_NOT_FOUND	1001

class MainEngine : public IFeedReaderEngine
{
public:
	MainEngine(MainState* mainState) : state(mainState) {};
	
        virtual set<__Tag*>     GetTags ();
        virtual set<__Feed*>    GetFeeds ();
        virtual list<__News*> GetFeedByNumber ( int feedID , int start , int count );
        virtual list<__News*> GetNews  ( int page , int count ) ;

	virtual int		AddTag ( string name );
	virtual int		DelTag ( int tagID );
	
	virtual int	        AddFeed ( string name , string url );
	virtual int             DelFeed ( int feedID );

	virtual int             AssignTags ( int feedID , int newsID , set<int> tags );
        virtual int             RemoveTags ( int feedID , int newsID , set<int> tags );

        virtual list<__News*> Search ( set<int> feeds , set<int> tagsPositive ,
                        set<int> tagsNegative , time_t since , time_t until );

protected:
	bool 			TagInList ( list<TCId>& lst , int tag );
	NewsItemConsulta* 	__GetNews ( int feedID , int newsID );
	void MainEngine::__GetNewsHelper(map<TCId,int>& feedPos, map<TCId,time_t>& maxDate,
		                multimap<time_t,NewsItemConsulta>& results,int count,int feedID);
	int  AddRemoveTags ( bool add , int feedID , int newsID , set<int>& tags );
			
	MainState*	state;
};
